/*
 * @Descripttion:
 * @version:
 * @Author: sueRimn
 * @Date: 2019-10-22 14:39:05
 * @LastEditors: sueRimn
 * @LastEditTime: 2020-08-26 11:05:27
 */
import {getArrIndex, reqFullScreen, exitFullScreen} from '@/util/tool'
const common = {
    namespaced: true,
    state: {
        isCollapse: false,
        tagList: JSON.parse(sessionStorage.getItem('tagList')) || [],
        tag: JSON.parse(sessionStorage.getItem('tag')) || {},
        isFullScreen: false,
        // 页面缓存配置
        keepAlive: [],
        // keepAlivePage: ['chart-detail', 'order', 'feedback', 'appFeadBack', 'log', 'systemLog', 'system'],
        // keepAlivePath: ['/index/chart-detail','/order/index', '/feedback/feedback', '/feedback/app-feedback', '/log/log', '/log/system-log', '/system/index']
        keepAlivePage: [
            'chart-detail', 
            'user',
            'childList', 
            'order', 
            'feedback', 
            'appFeadBack', 
            'log', 
            'systemLog', 
            'system',
            'invitation',
            'withdrawal',
            'index',
            'notice',
            'index'
        ],
        keepAlivePath: [
            '/index/chart-detail', 
            '/user/index',
            '/user/child', 
            '/order/index', 
            '/feedback/feedback', 
            '/feedback/app-feedback', 
            '/log/log', 
            '/log/system-log', 
            '/system/index',
            '/activity/invitation',
            '/activity/withdrawal',
            '/advertis/index',
            '/advertis/notice',
            '/hideapp/hideapp'
        ]
    },
    getters: {

    },
    mutations: {
        SET_COLLAPSE (state, params) {
            state.isCollapse = !state.isCollapse
        },
        ADD_TAG (state, params) {
            state.tag = params
            sessionStorage.setItem('tag', JSON.stringify(params))
            state.tagList.forEach((item, index, array) => {
                if (item.value === params.value) {
                    state.tagList[index].query = params.query
                }
            })
            var bool = state.tagList.some((item, index, array) => {
                return item.value == params.value
            })
            if (params.value === '/index/chart-detail') {
              state.tagList.forEach((item, index) => {
                if (item.value == params.value) {
                  item.label = params.label
                }
              })
            }
            if (bool) {
                return false
            } else {
                state.tagList.push(params)
                sessionStorage.setItem('tagList', JSON.stringify(state.tagList))
            }
        },
        CLOSE_TAG (state, params) {
            var i = getArrIndex(state.tagList, params.value)
            state.tagList.splice(i, 1)
            sessionStorage.setItem('tagList', JSON.stringify(state.tagList))
        },
        CLEAR_TAG (state, params) {
            state.tagList = []
            sessionStorage.setItem('tagList', JSON.stringify(state.tagList))
            state.tag = {}
            sessionStorage.setItem('tag', JSON.stringify(state.tag))
        },
        KEEP_ALIVE (state, params) {
            state.keepAlive = params
            console.log(state.keepAlive)
        },
        SET_FULL_SCREEN (state, params) {
            state.isFullScreen = !state.isFullScreen
            if (state.isFullScreen) {
                reqFullScreen()
                state.isCollapse = true
            } else {
                exitFullScreen()
                state.isCollapse = false
            }
        }
    },
    actions: {

    }
}
export default common
